import { Inject, Injectable, Scope } from '@nestjs/common';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { Cache } from 'cache-manager';

@Injectable({ scope: Scope.REQUEST })
export class RedisProvider {
  constructor(@Inject(CACHE_MANAGER) private cacheManager: Cache) {}

  getAllKeys(): Promise<string[]> {
    return this.cacheManager.store.keys();
  }

  get<T>(key: string): Promise<T | undefined> {
    return this.cacheManager.get<T>(key);
  }

  set<T>(key: string, value: T, ttl?: number): Promise<void> {
    return this.cacheManager.set(key, value, ttl);
  }

  del(key: string): Promise<void> {
    return this.cacheManager.del(key);
  }

  reset(): Promise<void> {
    return this.cacheManager.reset();
  }
}
